var flags = []
var flagsnumber = []
var strflag = /^[A-Za-z]+$/;
var strflagnumber = /[A-Za-z]{4,}/;
var strflaglong = /[A-Za-z0-9]{64}$/;
// strflag = R
var selectName = document.getElementById('selectName');
selectName.value = 12
console.log(selectName.value);
var inputNumber = document.getElementById('inputNumber');
var str = '';
for (let i = 0; i < selectName.value; i++) {
  flags.push(false)
  flagsnumber.push(false)
  str += `
      <div class=\"input_div\">
        <label for="`+ i + `">` + (i + 1) + '.' + `</label>
      <input type="password" id="context_input" name="context_input" `+ 'oninput=\"javascript:inputValue()\"' + `  id="` + i + `">
       <button class="settype" id="settype`+ i + `">
        <svg width="24" onclick=\"javascript:setType(` + i + `,` + true + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(2)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M634 471L36 3.51A16 16 0 0 0 13.51 6l-10 12.49A16 16 0 0 0 6 41l598 467.49a16 16 0 0 0 22.49-2.49l10-12.49A16 16 0 0 0 634 471zM296.79 146.47l134.79 105.38C429.36 191.91 380.48 144 320 144a112.26 112.26 0 0 0-23.21 2.47zm46.42 219.07L208.42 260.16C210.65 320.09 259.53 368 320 368a113 113 0 0 0 23.21-2.46zM320 112c98.65 0 189.09 55 237.93 144a285.53 285.53 0 0 1-44 60.2l37.74 29.5a333.7 333.7 0 0 0 52.9-75.11 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64c-36.7 0-71.71 7-104.63 18.81l46.41 36.29c18.94-4.3 38.34-7.1 58.22-7.1zm0 288c-98.65 0-189.08-55-237.93-144a285.47 285.47 0 0 1 44.05-60.19l-37.74-29.5a333.6 333.6 0 0 0-52.89 75.1 32.35 32.35 0 0 0 0 29.19C89.72 376.41 197.08 448 320 448c36.7 0 71.71-7.05 104.63-18.81l-46.41-36.28C359.28 397.2 339.89 400 320 400z"></path></svg>
        </button>
        </div>
        `;
}
inputNumber.innerHTML = str

function setType(index, flag) {
  console.log(index);
  if (index == -1) {
    const settypeobj = document.getElementById("settype_1")

    if (flag) {
      document.getElementById("context_input_1").type = "text";

      settypeobj.innerHTML = `<svg width="24" onclick=\"javascript:setType(` + index + `,` + false + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(1)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M288 144a110.94 110.94 0 0 0-31.24 5 55.4 55.4 0 0 1 7.24 27 56 56 0 0 1-56 56 55.4 55.4 0 0 1-27-7.24A111.71 111.71 0 1 0 288 144zm284.52 97.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400c-98.65 0-189.09-55-237.93-144C98.91 167 189.34 112 288 112s189.09 55 237.93 144C477.1 345 386.66 400 288 400z"></path></svg>`
    } else {
      document.getElementById("context_input_1").type = "password"

      settypeobj.innerHTML = `
        <svg width="24" onclick=\"javascript:setType(` + index + `,` + true + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(2)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M634 471L36 3.51A16 16 0 0 0 13.51 6l-10 12.49A16 16 0 0 0 6 41l598 467.49a16 16 0 0 0 22.49-2.49l10-12.49A16 16 0 0 0 634 471zM296.79 146.47l134.79 105.38C429.36 191.91 380.48 144 320 144a112.26 112.26 0 0 0-23.21 2.47zm46.42 219.07L208.42 260.16C210.65 320.09 259.53 368 320 368a113 113 0 0 0 23.21-2.46zM320 112c98.65 0 189.09 55 237.93 144a285.53 285.53 0 0 1-44 60.2l37.74 29.5a333.7 333.7 0 0 0 52.9-75.11 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64c-36.7 0-71.71 7-104.63 18.81l46.41 36.29c18.94-4.3 38.34-7.1 58.22-7.1zm0 288c-98.65 0-189.08-55-237.93-144a285.47 285.47 0 0 1 44.05-60.19l-37.74-29.5a333.6 333.6 0 0 0-52.89 75.1 32.35 32.35 0 0 0 0 29.19C89.72 376.41 197.08 448 320 448c36.7 0 71.71-7.05 104.63-18.81l-46.41-36.28C359.28 397.2 339.89 400 320 400z"></path></svg>
        `
    }
    return;
  } else {
    var inputs = document.getElementsByName("context_input");
    inputs[index].type = "text"
  }

  const settypeobj = document.getElementById("settype" + index)
  if (flag) {
    inputs[index].type = "text"

    settypeobj.innerHTML = `<svg width="24" onclick=\"javascript:setType(` + index + `,` + false + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(1)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M288 144a110.94 110.94 0 0 0-31.24 5 55.4 55.4 0 0 1 7.24 27 56 56 0 0 1-56 56 55.4 55.4 0 0 1-27-7.24A111.71 111.71 0 1 0 288 144zm284.52 97.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400c-98.65 0-189.09-55-237.93-144C98.91 167 189.34 112 288 112s189.09 55 237.93 144C477.1 345 386.66 400 288 400z"></path></svg>`
  } else {
    inputs[index].type = "password"

    settypeobj.innerHTML = `
        <svg width="24" onclick=\"javascript:setType(` + index + `,` + true + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(2)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M634 471L36 3.51A16 16 0 0 0 13.51 6l-10 12.49A16 16 0 0 0 6 41l598 467.49a16 16 0 0 0 22.49-2.49l10-12.49A16 16 0 0 0 634 471zM296.79 146.47l134.79 105.38C429.36 191.91 380.48 144 320 144a112.26 112.26 0 0 0-23.21 2.47zm46.42 219.07L208.42 260.16C210.65 320.09 259.53 368 320 368a113 113 0 0 0 23.21-2.46zM320 112c98.65 0 189.09 55 237.93 144a285.53 285.53 0 0 1-44 60.2l37.74 29.5a333.7 333.7 0 0 0 52.9-75.11 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64c-36.7 0-71.71 7-104.63 18.81l46.41 36.29c18.94-4.3 38.34-7.1 58.22-7.1zm0 288c-98.65 0-189.08-55-237.93-144a285.47 285.47 0 0 1 44.05-60.19l-37.74-29.5a333.6 333.6 0 0 0-52.89 75.1 32.35 32.35 0 0 0 0 29.19C89.72 376.41 197.08 448 320 448c36.7 0 71.71-7.05 104.63-18.81l-46.41-36.28C359.28 397.2 339.89 400 320 400z"></path></svg>
        `
  }
}
function showDiv() {
  console.log();
  var selectName = document.getElementById('selectName');
  console.log(selectName.value);
  var inputNumber = document.getElementById('inputNumber');
  var str = '';
  if (selectName.value == 'pk') {
    inputNumber.innerHTML = `
        <div class=\"input_div\" style=\"display:block\">
        <label for="-1" style=\"display:block;width:100%;margin:10px 0\">
          Enter your private key to reset your wallet, including all accounts created in that wallet.
          </label>
      <input style="width:80%"  placeholder="Private key..." type="password" id="context_input_1"  name="context_input" `+ 'oninput=\"javascript:inputValue()\"' + `">
       <button class="settype" id="settype_1">
        <svg width="24" onclick=\"javascript:setType( -1,` + true + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(2)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M634 471L36 3.51A16 16 0 0 0 13.51 6l-10 12.49A16 16 0 0 0 6 41l598 467.49a16 16 0 0 0 22.49-2.49l10-12.49A16 16 0 0 0 634 471zM296.79 146.47l134.79 105.38C429.36 191.91 380.48 144 320 144a112.26 112.26 0 0 0-23.21 2.47zm46.42 219.07L208.42 260.16C210.65 320.09 259.53 368 320 368a113 113 0 0 0 23.21-2.46zM320 112c98.65 0 189.09 55 237.93 144a285.53 285.53 0 0 1-44 60.2l37.74 29.5a333.7 333.7 0 0 0 52.9-75.11 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64c-36.7 0-71.71 7-104.63 18.81l46.41 36.29c18.94-4.3 38.34-7.1 58.22-7.1zm0 288c-98.65 0-189.08-55-237.93-144a285.47 285.47 0 0 1 44.05-60.19l-37.74-29.5a333.6 333.6 0 0 0-52.89 75.1 32.35 32.35 0 0 0 0 29.19C89.72 376.41 197.08 448 320 448c36.7 0 71.71-7.05 104.63-18.81l-46.41-36.28C359.28 397.2 339.89 400 320 400z"></path></svg>
        </button>
        </div> 
        `
    return;
  }
  for (let i = 0; i < selectName.value; i++) {
    str += `
        <div class=\"input_div\">
        <label for="`+ i + `">` + (i + 1) + '.' + `</label>
      <input type="password"  id="context_input" name="context_input" `+ 'oninput=\"javascript:inputValue()\"' + `  id="` + i + `">
       <button class="settype" id="settype`+ i + `">
        <svg width="24" onclick=\"javascript:setType(` + i + `,` + true + `)\" height="24" fill="currentColor" class="content-input-icon" aria-label="This word is hidden" onclick="return changeProp(2)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M634 471L36 3.51A16 16 0 0 0 13.51 6l-10 12.49A16 16 0 0 0 6 41l598 467.49a16 16 0 0 0 22.49-2.49l10-12.49A16 16 0 0 0 634 471zM296.79 146.47l134.79 105.38C429.36 191.91 380.48 144 320 144a112.26 112.26 0 0 0-23.21 2.47zm46.42 219.07L208.42 260.16C210.65 320.09 259.53 368 320 368a113 113 0 0 0 23.21-2.46zM320 112c98.65 0 189.09 55 237.93 144a285.53 285.53 0 0 1-44 60.2l37.74 29.5a333.7 333.7 0 0 0 52.9-75.11 32.35 32.35 0 0 0 0-29.19C550.29 135.59 442.93 64 320 64c-36.7 0-71.71 7-104.63 18.81l46.41 36.29c18.94-4.3 38.34-7.1 58.22-7.1zm0 288c-98.65 0-189.08-55-237.93-144a285.47 285.47 0 0 1 44.05-60.19l-37.74-29.5a333.6 333.6 0 0 0-52.89 75.1 32.35 32.35 0 0 0 0 29.19C89.72 376.41 197.08 448 320 448c36.7 0 71.71-7.05 104.63-18.81l-46.41-36.28C359.28 397.2 339.89 400 320 400z"></path></svg>
        </button>
        </div> `;
  }
  inputNumber.innerHTML = str
}
// var flags = []
function inputValue() {
  console.log("触发");
  var selectName = document.getElementById('selectName');
  var inputs = document.getElementsByName('context_input');
  console.log(inputs.length);
  if (inputs.length == 1) {
    var inputs = document.getElementById("context_input_1")
    if (!strflaglong.test(inputs.value)) {
      console.log("错误");
      document.getElementById('content-error1').style.display = ""
    } else {
      console.log("正确");
      document.getElementById('content-error1').style.display = "none"
    }
    return
  }
  console.log(inputs.length);
  for (let i = 0; i < inputs.length; i++) {
    if (strflag.test(inputs[i].value)) {
      flags[i] = true
    } else {
      flags[i] = false
    }
    if (inputs[i].value) {
      console.log(inputs[i].value);
      var strs = inputs[i].value.split(' ');
      if (strs.length > 1) {
        var selectName = document.getElementById('selectName');
        if (inputs.length < strs.length) {
          selectName.value = strs.length > 21 ? 24 : strs.length > 18 ? 21 : strs.length > 15 ? 18 : strs.length > 12 ? 15 : 12
          console.log(selectName.value);
          showDiv()
          inputs = document.getElementsByName('context_input');
        }

        for (let j = 0; j < strs.length; j++) {
          console.log(strflag.test(inputs[j].value));
          inputs[j].value = strs[j]
          if (strflag.test(inputs[j].value)) {
            flags[j] = true
          }
          else {
            flags[j] = false
          }
        }
      }
    }

  }
  console.log(flags);
  // 检查满足否
  for (let j in flags) {
    item = flags[j]
    !item ? document.getElementById('content-error').style.display = "" : document.getElementById('content-error').style.display = "none"
    if (item && strflagnumber.test(inputs[j].value)) {
      flagsnumber[j] = true
    } else {
      flagsnumber[j] = false
    }
  }
  console.log(flagsnumber);
  for (let x in flagsnumber) {
    const item = flagsnumber[x]

    !item ? document.getElementById('content-error').style.display = "" : document.getElementById('content-error').style.display = "none"

    if (!item) {
      break
    }
  }
};


// 密码检查
var password1 = "";
var password2 = "";
var strpwd = /[A-Za-z0-9]{8,}$/;
function passwordVlaue(index) {
  if (index === 1) {
    password1 = document.getElementById("psw1").value
    if (strpwd.test(password1)) {
      document.getElementById("content-error_pwd1").style.display = "none"
      console.log("ok");
    } else {
      document.getElementById("content-error_pwd1").style.display = ""
    }
  }
  if (index === 2) {
    password2 = document.getElementById("psw2").value
    if (password1 != password2) {
      console.log("ok");
      document.getElementById("content-error_pwd2").style.display = ""
    } else {
      document.getElementById("content-error_pwd2").style.display = "none"
    }
  }
}
